﻿<!--
   Extended Silverlight Toolkit – SAMPLE CODE

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

 ===========================================================================

  === IMPORTANT NETFLIX INFORMATION ===

   This sample application accesses data from the Netflix's OData Catalog API. 
   Before you compile this sample application, you must agree to the terms and conditions 
   of the Netflix API Terms of Use agreement. 

   The agreement is available here: http://developer.netflix.com/page/Api_terms_of_use
-->

<UserControl x:Class="Xceed.Silverlight.DataGrid.Samples.RemoteDataAccessSample"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:sldg="http://schemas.xceed.com/silverlight/xaml/datagrid"
             xmlns:sample="clr-namespace:Xceed.Silverlight.DataGrid.Samples"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="400">
    <UserControl.Resources>
        <ResourceDictionary>

            <!-- DataTemplate for a "full" star rating, to be used to star rating controls -->
            <DataTemplate x:Key="fullStarDataTemplate">
                <Grid Height="17.503"
            Width="18.058">
                    <Path Data="M10.3301,1.75C10.8101,1.75,13.3701,6.6,13.3701,6.6C13.3701,6.6,18.7001,7.58,18.8501,8.04C18.9901,8.51,15.2501,12.48,15.2501,12.48C15.2501,12.48,15.9801,17.939,15.5901,18.23C15.2001,18.51,10.3301,16.12,10.3301,16.12C10.3301,16.12,5.4501,18.51,5.0601,18.23C4.6701,17.939,5.4001,12.48,5.4001,12.48C5.4001,12.48,1.6601,8.51,1.8001,8.04C1.9501,7.58,7.2801,6.6,7.2801,6.6C7.2801,6.6,9.8401,1.75,10.3301,1.75z"
               StrokeStartLineCap="Round"
               Stretch="Fill"
               StrokeEndLineCap="Round"
               StrokeLineJoin="Round">
                        <Path.Fill>
                            <RadialGradientBrush Center="0.32475655879383225,0.2948194267000162"
                                    GradientOrigin="0.32475655879383225,0.2948194267000162"
                                    RadiusX="0.6767785021934019"
                                    RadiusY="0.7192158289718202">
                                <GradientStop Color="#FFFF8000"
                                Offset="1" />
                                <GradientStop Color="#FFF9F2D6" />
                                <GradientStop Color="#FFFFD200"
                                Offset="0.438" />
                            </RadialGradientBrush>
                        </Path.Fill>
                    </Path>
                    <Path Data="M10.3301,1.75C10.8101,1.75,13.3701,6.6,13.3701,6.6C13.3701,6.6,18.7001,7.58,18.8501,8.04C18.9901,8.51,15.2501,12.48,15.2501,12.48C15.2501,12.48,15.9801,17.939,15.5901,18.23C15.2001,18.51,10.3301,16.12,10.3301,16.12C10.3301,16.12,5.4501,18.51,5.0601,18.23C4.6701,17.939,5.4001,12.48,5.4001,12.48C5.4001,12.48,1.6601,8.51,1.8001,8.04C1.9501,7.58,7.2801,6.6,7.2801,6.6C7.2801,6.6,9.8401,1.75,10.3301,1.75z"
               StrokeStartLineCap="Round"
               Stretch="Fill"
               StrokeEndLineCap="Round"
               StrokeThickness="1"
               StrokeLineJoin="Round"
               Stroke="#33FFFFFF" />
                </Grid>
            </DataTemplate>

            <!-- DataTemplate for a "half" star rating, to be used to star rating controls -->
            <DataTemplate x:Key="halfStarDataTemplate">
                <Grid Height="17.504"
            Width="18.058">
                    <Path Data="M15.25,12.4805C15.25,12.4805,15.98,17.9395,15.59,18.2305C15.2,18.5095,10.33,16.1205,10.33,16.1205C10.33,16.1205,5.45,18.5095,5.06,18.2305C4.67,17.9395,5.4,12.4805,5.4,12.4805C5.4,12.4805,1.66,8.5095,1.8,8.0405C1.95,7.5805,7.28,6.6005,7.28,6.6005"
               StrokeStartLineCap="Round"
               Stretch="Fill"
               StrokeEndLineCap="Round"
               StrokeThickness="0"
               StrokeLineJoin="Round"
               Margin="0,4.851,3.15,0">
                        <Path.Fill>
                            <RadialGradientBrush Center="0.32475655879383225,0.2948194267000162"
                                    GradientOrigin="0.32475655879383225,0.2948194267000162"
                                    RadiusX="0.6767785021934019"
                                    RadiusY="0.7192158289718202">
                                <GradientStop Color="#FFFF8000"
                                Offset="1" />
                                <GradientStop Color="#FFF9F2D6" />
                                <GradientStop Color="#FFFFD200"
                                Offset="0.438" />
                            </RadialGradientBrush>
                        </Path.Fill>
                    </Path>
                    <Path Data="M10.3301,1.75C10.8101,1.75,13.3701,6.6,13.3701,6.6C13.3701,6.6,18.7001,7.58,18.8501,8.04C18.9901,8.51,15.2501,12.48,15.2501,12.48C15.2501,12.48,15.9801,17.939,15.5901,18.23C15.2001,18.51,10.3301,16.12,10.3301,16.12C10.3301,16.12,5.4501,18.51,5.0601,18.23C4.6701,17.939,5.4001,12.48,5.4001,12.48C5.4001,12.48,1.6601,8.51,1.8001,8.04C1.9501,7.58,7.2801,6.6,7.2801,6.6C7.2801,6.6,9.8401,1.75,10.3301,1.75z"
               StrokeStartLineCap="Round"
               Stretch="Fill"
               StrokeEndLineCap="Round"
               StrokeThickness="1"
               StrokeLineJoin="Round"
               Opacity="0.5"
               Margin="0,0,0,0.001">
                        <Path.Stroke>
                            <RadialGradientBrush Center="0.32475655879383225,0.2948194267000162"
                                    GradientOrigin="0.32475655879383225,0.2948194267000162"
                                    RadiusX="0.6767785021934019"
                                    RadiusY="0.7192158289718202">
                                <GradientStop Color="#FFFF8000"
                                Offset="1" />
                                <GradientStop Color="#FFF9F2D6" />
                                <GradientStop Color="#FFFFD200"
                                Offset="0.438" />
                            </RadialGradientBrush>
                        </Path.Stroke>
                    </Path>
                </Grid>
            </DataTemplate>

            <!-- DataTemplate for a "no" star rating, to be used to star rating controls -->
            <DataTemplate x:Key="noStarDataTemplate">
                <Grid Height="17.503"
            Width="18.058">
                    <Path Data="M10.3301,1.75C10.8101,1.75,13.3701,6.6,13.3701,6.6C13.3701,6.6,18.7001,7.58,18.8501,8.04C18.9901,8.51,15.2501,12.48,15.2501,12.48C15.2501,12.48,15.9801,17.939,15.5901,18.23C15.2001,18.51,10.3301,16.12,10.3301,16.12C10.3301,16.12,5.4501,18.51,5.0601,18.23C4.6701,17.939,5.4001,12.48,5.4001,12.48C5.4001,12.48,1.6601,8.51,1.8001,8.04C1.9501,7.58,7.2801,6.6,7.2801,6.6C7.2801,6.6,9.8401,1.75,10.3301,1.75z"
               StrokeStartLineCap="Round"
               Stretch="Fill"
               StrokeEndLineCap="Round"
               StrokeThickness="1"
               StrokeLineJoin="Round"
               Opacity="0.5">
                        <Path.Stroke>
                            <RadialGradientBrush Center="0.32475655879383225,0.2948194267000162"
                                    GradientOrigin="0.32475655879383225,0.2948194267000162"
                                    RadiusX="0.6767785021934019"
                                    RadiusY="0.7192158289718202">
                                <GradientStop Color="#FFFF8000"
                                Offset="1" />
                                <GradientStop Color="#FFF9F2D6" />
                                <GradientStop Color="#FFFFD200"
                                Offset="0.438" />
                            </RadialGradientBrush>
                        </Path.Stroke>
                    </Path>
                </Grid>
            </DataTemplate>

            <Style x:Key="textTrimmingStyle"
                   TargetType="TextBlock">
                <Setter Property="TextTrimming"
                        Value="WordEllipsis" />
                <Setter Property="VerticalAlignment"
                        Value="Center" />
            </Style>

            <Style x:Key="HyperlinkButtonStyle"
                TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <TextBlock Foreground="#FD9C02">
                            [www]
                            </TextBlock>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <!-- Return the NoBoxArt image when no uri is returned for a Title -->
            <sample:BoxArtImageSourceConverter x:Key="boxArtImageSourceConverter" />

            <ControlTemplate x:Key="tooltipTemplate"
                          TargetType="ToolTip">
                <Border Background="#FF2B2B2B"
                    BorderBrush="#FF161616"
                    BorderThickness="1"
                    Padding="4">
                    <ContentPresenter />
                </Border>
            </ControlTemplate>

            <!-- DataTemplate used to display the BoxArt -->
            <DataTemplate x:Key="boxArtCellContentTemplate">
                <ContentControl>
                    <ContentControl.ContentTemplate>
                        <DataTemplate>
                            <Image Source="{Binding Path=LargeUrl, Converter={StaticResource boxArtImageSourceConverter}}"
                                   Stretch="Uniform">
                                <ToolTipService.ToolTip>
                                    <ToolTip Template="{StaticResource tooltipTemplate}">
                                        <Image Source="{Binding LargeUrl}" />
                                    </ToolTip>
                                </ToolTipService.ToolTip>
                            </Image>
                        </DataTemplate>
                    </ContentControl.ContentTemplate>
                </ContentControl>
            </DataTemplate>

            <DataTemplate x:Key="synopsisCellContentTemplate">
                <ContentControl>
                    <ContentControl.ContentTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"
                                TextWrapping="Wrap"
                                TextTrimming="WordEllipsis">
                        <ToolTipService.ToolTip>
                           <ToolTip Template="{StaticResource tooltipTemplate}">
                              <TextBlock Text="{Binding}"
                                         TextWrapping="Wrap"
                                         TextTrimming="None"
                                         Foreground="White"
                                         MaxWidth="300" />
                           </ToolTip>
                        </ToolTipService.ToolTip>
                     </TextBlock>
                        </DataTemplate>
                    </ContentControl.ContentTemplate>
                </ContentControl>
            </DataTemplate>

            <sample:RatingConverter x:Key="ratingConverter"
                                 FullTemplate="{StaticResource fullStarDataTemplate}"
                                 HalfTemplate="{StaticResource halfStarDataTemplate}"
                                 EmptyTemplate="{StaticResource noStarDataTemplate}" />

            <DataTemplate x:Key="ratingCellContentTemplate">
                <ContentControl>
                    <ContentControl.ContentTemplate>
                        <DataTemplate>
                            <ItemsControl ItemsSource="{Binding Converter={StaticResource ratingConverter}}">
                                <ToolTipService.ToolTip>
                                    <ToolTip Template="{StaticResource tooltipTemplate}">
                                        <TextBlock Text="{Binding StringFormat=\{0:f1\}}"
                                         Foreground="White" />
                                    </ToolTip>
                                </ToolTipService.ToolTip>

                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                        </DataTemplate>
                    </ContentControl.ContentTemplate>
                </ContentControl>
            </DataTemplate>

            <DataTemplate x:Key="ratingGroupValueTemplate">
                <TextBlock Text="{Binding StringFormat=\{0:f1\}/5}" />
            </DataTemplate>

            <sample:SecondsToTimeSpanConverter x:Key="secondsToTimeSpanConverter" />

            <DataTemplate x:Key="runtimeCellContentTemplate">
                <ContentControl>
                    <ContentControl.ContentTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Converter={StaticResource secondsToTimeSpanConverter}}" />
                        </DataTemplate>
                    </ContentControl.ContentTemplate>
                </ContentControl>
            </DataTemplate>

            <!-- The Hyperlink can't be used because not set the same way in
                 Silverlight vs WPF. That's why we use a button and manage its click.-->
            <DataTemplate x:Key="hyperlinkCellContentTemplate">
                <ContentControl>
                    <ContentControl.ContentTemplate>
                        <DataTemplate>
                            <Button Style="{StaticResource HyperlinkButtonStyle}"
                             Cursor="Hand"
                             Click="HyperlinkButton_Click">
                            </Button>
                        </DataTemplate>
                    </ContentControl.ContentTemplate>
                </ContentControl>
            </DataTemplate>

            <!-- Style to display the text centered horizontally and vertically for text field -->
            <Style x:Key="centeredTextStyle"
                TargetType="TextBlock">
                <Setter Property="TextTrimming"
                    Value="WordEllipsis" />
                <Setter Property="HorizontalAlignment"
                    Value="Center" />
            </Style>

        </ResourceDictionary>
    </UserControl.Resources>

    <sldg:DataGridControl x:Name="dataGrid"
                         ReadOnly="True"
                         ItemsSource="{Binding}"
                         AutoCreateColumns="False"
                         RowHeight="60"
                         UnhandledDataException="OnDataGridUnhandledDataException">
        <sldg:DataGridControl.Columns>

            <!-- Display the BoxArt.SmallUrl as an image in a non sortable, non groupable Column -->
            <sldg:Column FieldName="BoxArt"
                      Title="Box Art"
                      AllowSort="False"
                      AllowGroup="False"
                      AllowFilter="False"
                      AllowResize="False"
                      CellHorizontalContentAlignment="Center"
                      Width="80"
                      CellContentTemplate="{StaticResource boxArtCellContentTemplate}" />

            <sldg:Column FieldName="Name"
                      AllowGroup="False"
                      AllowSort="True"
                      Width="215"
                      CellContentStyle="{StaticResource textTrimmingStyle}" />

            <sldg:Column FieldName="ShortSynopsis"
                      Title="Synopsis"
                      AllowGroup="False"
                      AllowSort="False"
                      AllowFilter="False"
                      Width="215"
                      CellContentTemplate="{StaticResource synopsisCellContentTemplate}" />

            <sldg:Column FieldName="AverageRating"
                      Title="User Rating"
                      AllowGroup="True"
                      AllowSort="True"
                      Width="100"
                      CellHorizontalContentAlignment="Center"
                      CellContentTemplate="{StaticResource ratingCellContentTemplate}">
                <sldg:Column.GroupDescription>
                    <sldg:DataGridGroupDescription PropertyName="AverageRating">
                        <sldg:DataGridGroupDescription.GroupConfiguration>
                            <sldg:DataGridGroupConfiguration GroupValueTemplate="{StaticResource ratingGroupValueTemplate}" />
                        </sldg:DataGridGroupDescription.GroupConfiguration>
                    </sldg:DataGridGroupDescription>
                </sldg:Column.GroupDescription>
            </sldg:Column>

            <sldg:Column FieldName="ReleaseYear"
                      AllowGroup="True"
                      AllowSort="True"
                      Title="Release Year"
                      Width="105"
                      SortDirection="Descending"
                      CellContentStyle="{StaticResource centeredTextStyle}" />

            <sldg:Column FieldName="Rating"
                      AllowGroup="True"
                      AllowSort="True"
                      CellContentStyle="{StaticResource centeredTextStyle}" />

            <sldg:Column FieldName="Type"
                      AllowGroup="True"
                      AllowSort="True"
                      Title="Media Type"
                      Width="105"
                      CellContentStyle="{StaticResource centeredTextStyle}" />

            <sldg:Column FieldName="Runtime"
                      Title="Runtime"
                      CellHorizontalContentAlignment="Center"
                      CellContentTemplate="{StaticResource runtimeCellContentTemplate}" />

            <sldg:Column FieldName="TinyUrl"
                      Title="Link"
                      AllowSort="False"
                      AllowGroup="False"
                      AllowFilter="False"
                      AllowResize="False"
                      Width="65"
                      CellHorizontalContentAlignment="Center"
                      CellContentTemplate="{StaticResource hyperlinkCellContentTemplate}" />

        </sldg:DataGridControl.Columns>

        <sldg:DataGridControl.FixedFooters>
            <sldg:NotificationControl />
        </sldg:DataGridControl.FixedFooters>

    </sldg:DataGridControl>
</UserControl>
